#!/bin/bash

set -e  # 一旦出错就退出

# 1.先清理构建目录和日志文件
rm -rf build
rm -f *.log
rm -rf Ipc

# 2.创建构建目录
mkdir -p build/lib

# 3.创建IPC通道
mkdir -p Ipc
touch Ipc/log.ipc Ipc/logic.ipc Ipc/master.ipc Ipc/game.ipc Ipc/log2db.ipc Ipc/db2work.ipc

# 构建测试程序
cd src/test
g++ main.cpp luaManager.cpp crc32.cpp -o ../../engine/client -llua5.4
cd ../../

# 4.执行命令开始编译
cd build
cmake ../src
make -j2

# 编译Go数据库程序，输出到 engine 目录
cd ..
cd src/db/logdb
go build -o ../../../engine/logdb
cd ../workdb
go build -o ../../../engine/workdb
cd ../../../engine

echo "Built target db"
